package com.example.healing.controller;

import com.example.healing.common.lang.Result;
import com.example.healing.entity.Comment;
import com.example.healing.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author neymar
 * @date 2021年11月30日 15:40
 */
@EnableSwagger2
@RestController
@Api(tags = "评论")
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * @author neymar
     * @date 2021/12/1 22:44
     * @param comment
     * @return com.example.healing.common.lang.Result
     * @description 添加评论
     */
    @RequiresAuthentication
    @ApiOperation(value = "添加评论（需要带token）")
    @PostMapping("/create")
    public Result create(@RequestBody @ApiParam("评论信息") Comment comment) {
        return commentService.create(comment);
    }

    /**
     * @author neymar
     * @date 2021/12/1 22:44
     * @param cid
     * @return com.example.healing.common.lang.Result
     * @description 删除评论
     */
    @RequiresAuthentication
    @ApiOperation(value = "删除评论（需要带token）")
    @DeleteMapping("/{cid}")
    public Result deleteComment(@PathVariable("cid") @ApiParam("评论id") String cid){
        return commentService.delete(cid);
    }

    @ApiOperation(value = "获取所有用户对该歌曲的评论（需要带token）")
    @GetMapping("/{songId}")
    public Result getAllComment(@PathVariable("songId") @ApiParam("歌曲id") String songId) {
        return commentService.getComment(songId);
    }

    @RequiresAuthentication
    @ApiOperation(value = "获取当前用户对该歌曲的评论（需要带token）")
    @GetMapping("/{songId}/{uid}")
    public Result getUserComment(@PathVariable("songId") @ApiParam("歌曲id") String songId, @PathVariable("uid") @ApiParam("用户id") String uid) {
        return commentService.getUserComment(songId,uid);
    }
}
